//: Filename : test.cpp
//: test

#include "test.h"
using namespace std;

/*
 *testHelloWorld
 */
void testHelloWorld(int argc, char* argv[])
{
    cout << "hi" << endl;
    MPI_Init(&argc, &argv);
    int rankid, numprocs, version, subversion;
    int namelen;
    char processor_name[MPI_MAX_PROCESSOR_NAME];
    MPI_Comm_rank(MPI_COMM_WORLD, &rankid);
    MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
    MPI_Get_processor_name(processor_name, &namelen);
    MPI_Get_version(&version, &subversion);
    //cout << namelen << endl;
    cout << rankid << " of " << numprocs << " on " << processor_name << endl;
    cout << "version:" << version << "." << subversion << endl;
    MPI_Finalize();
} //: testHelloWorld

/*
 * testSendRecv
 */
void testSendRecv(int argc, char* argv[])
{

    MPI_Init(&argc, &argv);
    int rankid, numprocs;
    int namelen;
    MPI_Status status;
    char processor_name[MPI_MAX_PROCESSOR_NAME];
    MPI_Comm_rank(MPI_COMM_WORLD, &rankid);
    MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
    MPI_Get_processor_name(processor_name, &namelen);

    if (rankid==0)
    {
        char message[] = "Hello process 1!";
        MPI_Send(message, strlen(message), MPI_CHAR, 2, 256, MPI_COMM_WORLD);
        message[1] = 'd';
        MPI_Send(message, strlen(message), MPI_CHAR, 1, 256, MPI_COMM_WORLD);
    } else if (rankid==2)
    {
        char message[20];
        //MPI_Recv(message, 100, MPI_CHAR, 0, 256, MPI_COMM_WORLD, &status);
        cout << "Received:" << message <<  endl;
    }
    cout << "rankid:" << rankid <<endl;
    MPI_Finalize();
} //: testSendRecv

/*
 * testWTIME
 */
void testWTIME(int argc, char* argv[])
{
    /*
       int rankid, numprocs, namelen;
       char processor_name[MPI_MAX_PROCESSOR_NAME];
       MPI_Comm_rank(MPI_COMM_WORLD, &rankid);
       MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
       MPI_Get_processor_name(processor_name, &namelen);
       */

    int err = 0;
    double t1, t2; 
    double tick;

    MPI_Init(&argc, &argv);
    t1 = MPI_Wtime();
    t2 = MPI_Wtime();

    if (t1-t2>0.1 || t2 > t2)
    {
        err++;
        cerr << "We get a strange results:!" 
            << t1 << "     " << t2 << endl;
    }

    for(int i=0; i < 10; i++)
    {
        t1 = MPI_Wtime();
        sleep(1);
        t2 = MPI_Wtime();

        if ((t2 - t1) >= (1.0 - 0.01) && t2 - t1 <= 5.0) break;
        if (t2 - t1 > 5.0) i = 9;
        if (i==10)
        {
            cerr << "Timer around sleep(1) did not give 1 second; give "
                << t2-t1 << endl;
        }
        tick = MPI_Wtick();
        if (tick > 1.0 || tick < 0.0)
        {
            err++;
            cerr << "MPI_Wtick gave a strange result:" << tick << endl;
        }



    }
    MPI_Finalize();
} //: testWTIME

/*
 * testMasterNode
 */

void testMasterNode(int argc, char* argv[])
{
    int masternode = 0;
    int rankid, size;
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rankid);
    MPI_Comm_size(MPI_COMM_WORLD, &size);
    for (int i=0; i<argc; i++)
    {
        cout << "rankid = " << rankid << "  procs = " << size 
            << "argv[" << i << "] = " << argv[i] << endl;
        if (argv[i] && strcmp("lastmaster", argv[i]))
        {
            masternode = size - 1;
        }
    }
    if (rankid == masternode)
    {
        cout << rankid <<" is the masternode!" << endl;
        MPI_Abort(MPI_COMM_WORLD, 100);
    } else 
    {
        cout << rankid << " is not a masternode barrier!" << endl;
        MPI_Barrier(MPI_COMM_WORLD);
    }

    MPI_Finalize();
} //: testMasterNode

/*
 * testTransitData
 */
void testTransitData(int argc, char* argv[])
{
    int procid, procsNum, namelen;
    char processor_name[MPI_MAX_PROCESSOR_NAME];
    MPI_Status status;

    MPI_Init(&argc, & argv);

    MPI_Comm_rank(MPI_COMM_WORLD, &procid);
    MPI_Comm_size(MPI_COMM_WORLD, &procsNum);
    MPI_Get_processor_name(processor_name, &namelen);

    cout << "procsNum:" << procsNum
        << "procid:" << procid << endl;

    double value = 100.0;;
    while (value >= 0.0 )
    {
        if (procid == 0)
        {
            cin >> value;

            if (procsNum > 1)
            {
                MPI_Send(&value, 1, MPI_DOUBLE, procid+1, 
                        100, MPI_COMM_WORLD);
                cout << procid << " => " 
                    << procid+1 << "  " << value << endl;
            }

        } else
        {
            MPI_Recv(&value, 1, MPI_DOUBLE, 
                    procid-1, 100, MPI_COMM_WORLD, &status);
            cout << procid << " <= " 
                << procid-1 << "  " << value << endl;
            if (procid < procsNum - 1)
            {
                MPI_Send(&value, 1, MPI_DOUBLE, procid+1, 
                        100, MPI_COMM_WORLD);
                cout << procid << " => " 
                    << procid+1 << "  " << value << endl;  
            } 
        }
        MPI_Barrier(MPI_COMM_WORLD);
    } 

    MPI_Finalize();
} //: testTransitData

/*
 *testSayHello
 */
void testSayHello(int argc, char* argv[])
{
    int procId, procsNum;
    char processorName[MPI_MAX_PROCESSOR_NAME];
    int nameLen;
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &procId);
    MPI_Comm_size(MPI_COMM_WORLD, &procsNum);
    MPI_Get_processor_name(processorName, &nameLen);
    MPI_Finalize();
} //: testSayHello

/*
 * testArr
 */
void testArr(int argc, char* argv[])
{
    double a[1000][1000];
    int maxIter = 1000;
    int iter = 0;
    MPI_Init(&argc, &argv);
    while(iter < maxIter)
    {
        for(int i=0; i<1000;i++)
        {
            for(int j=0; j < 1000; j++) a[i][j]= i+j;
        }
        iter++;
    }
    MPI_Finalize();
} //: testArr

/*
 *testMutualHello
 */
void testMutualHello(int argc, char* argv[])
{
    int procid, procsNum, nameLen;
    char processorName[MPI_MAX_PROCESSOR_NAME];
    MPI_Status status;

    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &procid);
    MPI_Comm_size(MPI_COMM_WORLD, &procsNum);
    MPI_Get_processor_name(processorName, &nameLen);

    if (procsNum < 2)
    {
        cout << "The number of processors is no less than 2!" 
            << endl;
        MPI_Abort(MPI_COMM_WORLD, 100);
    }

    cout << "Processor " << procid 
        << " is alive on processorName!" 
        << endl;
    MPI_Barrier(MPI_COMM_WORLD);

    int buffer[2];
    int tag = 1;
    for(int node = 0; node < procsNum; node++)
    {
        if (node!=procid)
        {
            buffer[0] = procid;
            buffer[1] = node;
            MPI_Send(buffer, 2, MPI_INT, 
                    node, tag, MPI_COMM_WORLD);
            MPI_Recv(buffer, 2, MPI_INT, 
                    node, tag, MPI_COMM_WORLD, &status);
            if(buffer[0] != node || buffer[1] != procid)
            {
                cout << "Mismatch on hello from " 
                    << node << " to " 
                    << procid << endl;
            } else 
            {
                cout << "Hello from " << node 
                    << " to " << procid << endl;
            }
        }

    }


    MPI_Finalize();
} //: testMutualHello

/*
*testAnyHello
 */
void testAnyHello(int argc, char* argv[])
{
    int rankid, procsNum, nameLen, buf[1];
    char processor_name[MPI_MAX_PROCESSOR_NAME];

    MPI_Init(&argc, &argv);
    MPI_Status status;

    MPI_Comm_rank(MPI_COMM_WORLD, &rankid);
    MPI_Comm_size(MPI_COMM_WORLD, &procsNum);
    MPI_Get_processor_name(processor_name, &nameLen);

    if (rankid == 0)
    {
        for(int i = 0; i < 100 * (procsNum - 1); i++)
        {
            MPI_Recv(buf, 1, MPI_INT, MPI_ANY_SOURCE,
                    MPI_ANY_TAG, MPI_COMM_WORLD, &status);
            cout << rankid << " is receiving " << buf[0] 
                <<" from "
                << status.MPI_SOURCE << " with " 
                << status.MPI_TAG << endl;
        }
    } else
    {
        for(int i=0; i<100; i++)
        {
            buf[0] = rankid+i;
            MPI_Send(buf, 1, MPI_INT, 0, i, MPI_COMM_WORLD);
        }
    }

    MPI_Finalize();

} //: testAnyHello

/*
 *testJacobi
 */
void testJacobi(int argc, char* argv[])
{
    int rankid, procsNum, nameLen;
    char processorName[MPI_MAX_PROCESSOR_NAME];
    int totalCol, totalRow;

    MPI_Init(&argc, &argv);
    MPI_Status status;
    MPI_Comm_rank(MPI_COMM_WORLD, &rankid); 
    MPI_Comm_size(MPI_COMM_WORLD, &procsNum);
    MPI_Get_processor_name(processorName, &nameLen);

    totalRow = 8;
    totalCol = 32;
    int myRow = totalRow;
    int myCol = totalCol / procsNum;
    int startCol, endCol;
    double Arr[myRow][myCol+2];
    double tempArr[myRow][myCol+2];
    double buf[myRow];


    if(rankid == 0)
    {
        for(int i=0; i<myRow; i++)
        {
            Arr[i][1] = 32;
        }
        for(int i=0; i<myRow; i++)
        {
            for(int j=2; j< myCol+1; j++)
            {
                Arr[i][j] = 1;
            }
        }
    } else
    {
        for(int i=0; i<myRow; i++)
        {
            for(int j=1; j<= myCol; j++)
            {
                Arr[i][j] = 1;
            }
        }
    }

    /*
    if(rankid == 0)
    {
        for(int i=0; i<myRow; i++)
        {
            for(int j=0; j< myCol+2; j++)
            {
                cout << Arr[i][j] << "  "; 
            }
            cout << endl;
        }

    }
    */

    int flag = 200;

    
    while (flag)
    {
        if (rankid == 0)
        {
            for(int i=0; i<myRow; i++) buf[i] = Arr[i][myCol];
            /*
            MPI_Send(buf, myRow, MPI_DOUBLE, rankid+1, 99, MPI_COMM_WORLD);
            MPI_Recv(buf, myRow, MPI_DOUBLE, 
                    rankid+1, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
                    */
            MPI_Sendrecv_replace(buf, myRow, MPI_DOUBLE, rankid+1, 99, 
                    rankid+1, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
            for(int i=0; i<myRow; i++) Arr[i][myCol+1] = buf[i];
            startCol = 2;
            endCol = myCol;
        } else if (rankid == procsNum-1)
        {
            for(int i=0; i<myRow; i++) buf[i] = Arr[i][1];
            /*
            MPI_Send(buf, myRow, MPI_DOUBLE, rankid-1, 99, MPI_COMM_WORLD);
            MPI_Recv(buf, myRow, MPI_DOUBLE, 
                    rankid-1, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
                    */

            MPI_Sendrecv_replace(buf, myRow, MPI_DOUBLE, rankid-1, 99, 
                    rankid-1, MPI_ANY_TAG, MPI_COMM_WORLD, &status);

            for(int i=0; i<myRow; i++) Arr[i][0] = buf[i];
            startCol = 1;
            endCol = myCol-1;
        } else
        {
            /*
            for(int i=0; i<myRow; i++) buf[i] = Arr[i][1];
            MPI_Send(buf, myRow, MPI_DOUBLE, rankid-1, 99, MPI_COMM_WORLD);

            for(int i=0; i<myRow; i++) buf[i] = Arr[i][myCol];
            MPI_Send(buf, myRow, MPI_DOUBLE, rankid+1, 99, MPI_COMM_WORLD);

            MPI_Recv(buf, myRow, MPI_DOUBLE, 
                    rankid-1, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
            for(int i=0; i<myRow; i++) Arr[i][0] = buf[i];

            MPI_Recv(buf, myRow, MPI_DOUBLE, 
                    rankid+1, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
            for(int i=0; i<myRow; i++) Arr[i][myCol+1] = buf[i];
            */

            for(int i=0; i<myRow; i++) buf[i] = Arr[i][1];
            MPI_Sendrecv_replace(buf, myRow, MPI_DOUBLE, rankid-1, 99, 
                    rankid-1, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
            for(int i=0; i<myRow; i++) Arr[i][0] = buf[i];

            for(int i=0; i<myRow; i++) buf[i] = Arr[i][myCol];
            MPI_Sendrecv_replace(buf, myRow, MPI_DOUBLE, rankid+1, 99, 
                    rankid+1, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
            for(int i=0; i<myRow; i++) Arr[i][myCol+1] = buf[i];

            startCol = 1;
            endCol = myCol;

        }

        for(int i=1; i<myRow-1; i++)
        {
            for(int j=startCol; j<=endCol; j++)
            {
                tempArr[i][j] = 0.25 * (Arr[i][j-1] + Arr[i][j+1]
                        + Arr[i-1][j] + Arr[i+1][j]);
            }
        }

        for(int i=1; i<myRow-1; i++)
        {
            for(int j=startCol; j<=endCol; j++)
            {
                Arr[i][j] = tempArr[i][j];
            }
        }
        flag--;

        MPI_Barrier(MPI_COMM_WORLD);
    }

    if(rankid == 0)
    {
        for(int i=0; i<myRow; i++)
        {
            for(int j=0; j< myCol+2; j++)
            {
                cout << Arr[i][j] << "  "; 
            }
            cout << endl;
        }

    }


    MPI_Finalize();

} //: testJacobi

/*
 *testBcast
 */
void testBcast(int argc, char* argv[])
{
    int rankid, masterid, nameLen, procsNum;
    char processorName[MPI_MAX_PROCESSOR_NAME];
    int row, col;
    row = col = 10;
    double A[row][col], B[col], buf[col], C[col];

    MPI_Init(&argc, &argv);
    MPI_Status status;
    masterid = 0;

    MPI_Comm_rank(MPI_COMM_WORLD, &rankid);
    MPI_Comm_size(MPI_COMM_WORLD, &procsNum);
    MPI_Get_processor_name(processorName, &nameLen);

    if (rankid == masterid)
    {
        int numSend = 0;
        for(int i=0; i<row; i++)
        {
            for(int j=0; j<col;j++)
            {
                A[i][j] = i + j;
            }
        }
        for(int j=0; j<col; j++) B[j] = j;

        MPI_Bcast(B, row, MPI_DOUBLE, masterid, MPI_COMM_WORLD);
        for(int i=0; i<min(procsNum-1, row); i++)
        {
            for(int j=0; j<col; j++) buf[j] = A[i][j];
            MPI_Send(buf, col, MPI_DOUBLE, i+1, i, MPI_COMM_WORLD);
            numSend++;
        }

        for(int i=0; i<row; i++)
        {
            double result;
            MPI_Recv(&result, col, MPI_DOUBLE, MPI_ANY_SOURCE, 
                    MPI_ANY_TAG, MPI_COMM_WORLD, &status);
            C[status.MPI_TAG] = result;
            if(numSend < row)
            {
                for(int j=0; j<col; j++) buf[j] = A[numSend][j];
                MPI_Send(buf, col, MPI_DOUBLE,  status.MPI_SOURCE, 
                        numSend, MPI_COMM_WORLD);
                numSend++;
            } else
            {
                MPI_Send(&result, 1, MPI_DOUBLE, status.MPI_SOURCE, 
                        row, MPI_COMM_WORLD);
            }

            //cout << i << endl;
        }
    } else
    {
        bool flag = true;
        MPI_Bcast(B, col, MPI_DOUBLE, masterid, MPI_COMM_WORLD);
        while (flag)
        {
            MPI_Recv(buf, col, MPI_DOUBLE, masterid, MPI_ANY_TAG, 
                    MPI_COMM_WORLD, &status);
            if (status.MPI_TAG != row)
            {
                double result = 0;
                for(int j=0; j<col; j++) result += buf[j] * B[j];
                MPI_Send(&result, 1, MPI_DOUBLE, masterid, 
                        status.MPI_TAG, MPI_COMM_WORLD);

            } else
            {
                flag = false;
            }

        }
    }
    if(rankid == masterid)
    {
        for(int j=0; j<col; j++)
        {
            cout << "C[" << j <<"] = " << C[j] << endl;
        }
    }

    MPI_Finalize();
} //: testBcast

/*
 *testStruct
 */
void testStruct(int argc, char* argv[])
{
    int rankid, rankSize, nameLen;
    char procsName[MPI_MAX_PROCESSOR_NAME];
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rankid);
    MPI_Comm_size(MPI_COMM_WORLD, &rankSize);
    MPI_Status status;
    man xm;
    xm.age = 20;
    xm.scores[0] = 90;
    xm.scores[1] = 95;

    MPI_Datatype myvar;
    MPI_Datatype old_types[3];
    MPI_Aint indices[3];
    old_types[0] = MPI_INT;
    old_types[1] = MPI_DOUBLE;
    old_types[2] = MPI_DOUBLE;
    int blocklens[3];
    blocklens[0] = 1;
    blocklens[1] = 2;
    blocklens[2] = 6;

    MPI_Address(&xm.age, &indices[0]);
    MPI_Address(&xm.scores, &indices[1]);
    MPI_Address(&xm.tt, &indices[2]);

    indices[2] -= indices[0];
    indices[1] -= indices[0];
    indices[0] = 0;

    MPI_Type_struct(3, blocklens, indices, old_types, &myvar);
    MPI_Type_commit(&myvar);

    if(rankid==0)
    {
        man* a = new man[2];
        a[0].age=11;
        a[0].scores[0] = 40;
        a[0].scores[1] = 50;
        for(int i=0; i<2; i++)
        {
            for(int j=0; j<3; j++)
            {
                a[0].tt[i][j] = i+j;
            }
        }
        a[1].age=30;
        a[1].scores[0] = 50;
        a[1].scores[1] = 60;
        for(int i=0; i<2; i++)
        {
            for(int j=0; j<3; j++)
            {
                a[1].tt[i][j] = (i+1)*(j+1)+1;
            }
        }

        MPI_Send(a, 2, myvar, 1, 1, MPI_COMM_WORLD);
    } else if(rankid==1)
    {
        man* b = new man[2];
        MPI_Recv(b, 2, myvar, 0, 1, 
                MPI_COMM_WORLD, &status);
        for(int i=0; i<2; i++)
        {
            cout << b[i].age << endl;
            cout << b[i].scores[0] << endl;
            cout << b[i].scores[1] << endl;
            for(int i=0; i<2; i++)
            {
                for(int j=0; j<3; j++)
                {
                    cout << b[i].tt[i][j] << " ";
                }
                cout << endl;
            }
            cout << endl;

        }
    }

    MPI_Finalize();
} //: testStruct

/*
 *testStruct2
 */
void testStruct2(int argc, char* argv[])
{
    int rankid, rankSize, nameLen;
    int _unum, _vnum;
    int count=100;
    _unum = count;
    _vnum = count;
    int _cParametersNum = 4;
    char procsName[MPI_MAX_PROCESSOR_NAME];
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rankid);
    MPI_Comm_size(MPI_COMM_WORLD, &rankSize);
    MPI_Status status;
    MPI_Request request;
    MyStruct* tempStruct = new MyStruct;
    tempStruct->cParam = new double[_cParametersNum];
    tempStruct->g = new double[_unum * _vnum];
    tempStruct->f = new double[_unum * _vnum];
    tempStruct->h = new double[_unum * _vnum];
    tempStruct->lmd_tau[0] = -2;
    tempStruct->lmd_tau[1] = -3;
    tempStruct->tag = -1000;
    tempStruct->x = -1.0;
    tempStruct->y = -1.0;
    tempStruct->area = -1.0;

    int blocklens[] = {1, 1, 1, 1, 2,
        _cParametersNum, 
        _unum*_vnum, 
        _unum*_vnum, 
        _unum*_vnum};


    MPI_Aint indices[9];
    MPI_Datatype old_types[9];
    for(int i=1; i<9; i++) old_types[i] = MPI_DOUBLE;
    old_types[0] = MPI_INT;
    MPI_Address(tempStruct, &indices[0]);
    MPI_Address(&(tempStruct->x), &indices[1]);
    MPI_Address(&(tempStruct->y), &indices[2]);
    MPI_Address(&(tempStruct->area), &indices[3]);

    MPI_Address(&(tempStruct->lmd_tau[0]), &indices[4]);
    MPI_Address(&(tempStruct->cParam[0]), &indices[5]);
    MPI_Address(&(tempStruct->g[0]), &indices[6]);
    MPI_Address(&(tempStruct->f[0]), &indices[7]);
    MPI_Address(&(tempStruct->h[0]), &indices[8]);

    for(int i=0; i<8; i++)
    {
        indices[8-i] = indices[8-i]-indices[0];

    }
    indices[0] = 0;
    /*
     *if (rankid==0)
     *{
     *    cout << tempStruct << endl;
     *    cout << &(*tempStruct) << endl;
     *    cout << &(tempStruct->tag) << endl;
     *    cout << &tempStruct->tag << endl;
     *}
     */

    MPI_Datatype myvar;
    MPI_Type_struct(9, blocklens, indices, old_types, &myvar);
    MPI_Type_commit(&myvar);

    for(int i=0; i<rankSize;i++)
    {
        if(i!=rankid)
        {
            /*
             *for(int j=0; j<_cParametersNum; j++)
             *{
             *    tempStruct->cParam[j] = i;
             *}
             *for(int j=0; j<_unum*_vnum; j++)
             *{
             *    tempStruct->g[j] = i;
             *    tempStruct->f[j] = i;
             *    tempStruct->h[j] = i;
             *}
             */
            //send
            /*
             *MPI_Isend(tempStruct, 1, myvar, 
             *        i, 99, MPI_COMM_WORLD, &request);
             */
            if (i>rankid)
            {
                MPI_Send(tempStruct, 1, myvar, 
                    i, 99, MPI_COMM_WORLD);
                //recv
                MPI_Recv(tempStruct, 1, myvar, 
                    i, 99, MPI_COMM_WORLD, &status);
            } else
            {
                MPI_Recv(tempStruct, 1, myvar, 
                    i, 99, MPI_COMM_WORLD, &status);
                MPI_Send(tempStruct, 1, myvar, 
                    i, 99, MPI_COMM_WORLD);
            }
        }
    }

    /*
    MPI_Barrier(MPI_COMM_WORLD);
    // send
    for(int i=0; i<rankSize; i++)
    {
        if(i!=rankid)
        {
            MPI_Recv(tempStruct, 1, myvar, 
                    i, 99, MPI_COMM_WORLD, &status);
            if(i==0 && rankid == 2)
            {
                cout << tempStruct->tag << endl;
                cout << tempStruct->x << endl;
                cout << tempStruct->y << endl;
                cout << tempStruct->area << endl;
                cout << tempStruct->lmd_tau[0] << endl;
                cout << tempStruct->lmd_tau[1] << endl;
                cout << tempStruct->cParam[2] << endl;
                cout << tempStruct->g[2] << endl;
                cout << tempStruct->f[2] << endl;
                cout << tempStruct->h[2] << endl;
            }
        }
    }
    */

    delete[] tempStruct->cParam;
    delete[] tempStruct->g;
    delete[] tempStruct->f;
    delete[] tempStruct->h;
    MPI_Type_free(&myvar);


    MPI_Finalize();
} //: testStruct2

///:~
